/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ms.unicorn.ui.styles.impl;

import ms.unicorn.ui.styles.CollapsableConstraint;
import ms.unicorn.ui.styles.StylesPackage;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.Size;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Collapsable Constraint</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ms.unicorn.ui.styles.impl.CollapsableConstraintImpl#getCollapsedSize <em>Collapsed Size</em>}</li>
 *   <li>{@link ms.unicorn.ui.styles.impl.CollapsableConstraintImpl#getExpandedSize <em>Expanded Size</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class CollapsableConstraintImpl extends EObjectImpl implements CollapsableConstraint {
	/**
	 * The cached value of the '{@link #getCollapsedSize() <em>Collapsed Size</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCollapsedSize()
	 * @generated
	 * @ordered
	 */
	protected Size collapsedSize;

	/**
	 * The cached value of the '{@link #getExpandedSize() <em>Expanded Size</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getExpandedSize()
	 * @generated
	 * @ordered
	 */
	protected Size expandedSize;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected CollapsableConstraintImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return StylesPackage.Literals.COLLAPSABLE_CONSTRAINT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public Size getCollapsedSize() {
		if (collapsedSize == null)
			collapsedSize = NotationFactory.eINSTANCE.createSize();
		return collapsedSize;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetCollapsedSize(Size newCollapsedSize, NotificationChain msgs) {
		Size oldCollapsedSize = collapsedSize;
		collapsedSize = newCollapsedSize;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, StylesPackage.COLLAPSABLE_CONSTRAINT__COLLAPSED_SIZE, oldCollapsedSize, newCollapsedSize);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCollapsedSize(Size newCollapsedSize) {
		if (newCollapsedSize != collapsedSize) {
			NotificationChain msgs = null;
			if (collapsedSize != null)
				msgs = ((InternalEObject)collapsedSize).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - StylesPackage.COLLAPSABLE_CONSTRAINT__COLLAPSED_SIZE, null, msgs);
			if (newCollapsedSize != null)
				msgs = ((InternalEObject)newCollapsedSize).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - StylesPackage.COLLAPSABLE_CONSTRAINT__COLLAPSED_SIZE, null, msgs);
			msgs = basicSetCollapsedSize(newCollapsedSize, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, StylesPackage.COLLAPSABLE_CONSTRAINT__COLLAPSED_SIZE, newCollapsedSize, newCollapsedSize));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public Size getExpandedSize() {
		if (expandedSize == null)
			expandedSize = NotationFactory.eINSTANCE.createSize();
		return expandedSize;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetExpandedSize(Size newExpandedSize, NotificationChain msgs) {
		Size oldExpandedSize = expandedSize;
		expandedSize = newExpandedSize;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, StylesPackage.COLLAPSABLE_CONSTRAINT__EXPANDED_SIZE, oldExpandedSize, newExpandedSize);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setExpandedSize(Size newExpandedSize) {
		if (newExpandedSize != expandedSize) {
			NotificationChain msgs = null;
			if (expandedSize != null)
				msgs = ((InternalEObject)expandedSize).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - StylesPackage.COLLAPSABLE_CONSTRAINT__EXPANDED_SIZE, null, msgs);
			if (newExpandedSize != null)
				msgs = ((InternalEObject)newExpandedSize).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - StylesPackage.COLLAPSABLE_CONSTRAINT__EXPANDED_SIZE, null, msgs);
			msgs = basicSetExpandedSize(newExpandedSize, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, StylesPackage.COLLAPSABLE_CONSTRAINT__EXPANDED_SIZE, newExpandedSize, newExpandedSize));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case StylesPackage.COLLAPSABLE_CONSTRAINT__COLLAPSED_SIZE:
				return basicSetCollapsedSize(null, msgs);
			case StylesPackage.COLLAPSABLE_CONSTRAINT__EXPANDED_SIZE:
				return basicSetExpandedSize(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case StylesPackage.COLLAPSABLE_CONSTRAINT__COLLAPSED_SIZE:
				return getCollapsedSize();
			case StylesPackage.COLLAPSABLE_CONSTRAINT__EXPANDED_SIZE:
				return getExpandedSize();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case StylesPackage.COLLAPSABLE_CONSTRAINT__COLLAPSED_SIZE:
				setCollapsedSize((Size)newValue);
				return;
			case StylesPackage.COLLAPSABLE_CONSTRAINT__EXPANDED_SIZE:
				setExpandedSize((Size)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case StylesPackage.COLLAPSABLE_CONSTRAINT__COLLAPSED_SIZE:
				setCollapsedSize((Size)null);
				return;
			case StylesPackage.COLLAPSABLE_CONSTRAINT__EXPANDED_SIZE:
				setExpandedSize((Size)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case StylesPackage.COLLAPSABLE_CONSTRAINT__COLLAPSED_SIZE:
				return collapsedSize != null;
			case StylesPackage.COLLAPSABLE_CONSTRAINT__EXPANDED_SIZE:
				return expandedSize != null;
		}
		return super.eIsSet(featureID);
	}

	@Override
	public void setCollapsedSize(int width, int height) {
		getCollapsedSize().setWidth(width);
		getCollapsedSize().setHeight(height);
	}

	@Override
	public Dimension getExpandedDimension() {
		return new Dimension(getExpandedSize().getWidth() , getExpandedSize().getHeight());
	}

	@Override
	public Dimension getCollapsedDimension() {
		return new Dimension(getCollapsedSize().getWidth(), getCollapsedSize().getHeight());
	}

	@Override
	public void setExpandedSize(int width, int height) {
		getExpandedSize().setWidth(width);
		getExpandedSize().setHeight(height);
	}
} //CollapsableConstraintImpl
